package cn.lynch.bbs.dao.impl;

import java.sql.SQLException;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Projections;
import org.springframework.orm.hibernate3.HibernateCallback;

import cn.lynch.bbs.dao.CategoryDao;
import cn.lynch.bbs.dao.PropertyFilter;
import cn.lynch.bbs.dao.SimpleHibernateDao;
import cn.lynch.bbs.domain.Category;

public class CategoryDaoImpl extends SimpleHibernateDao<Category, String> implements
		CategoryDao {

	@Override
	public int findMaxDisplayIndex() {
		
		Object result = hibernateTemplate.execute(new HibernateCallback() {
			
			@Override
			public Object doInHibernate(Session session) throws HibernateException,
					SQLException {
				
				return session.createCriteria(Category.class)
							.setProjection(Projections.max("displayIndex"))
							.uniqueResult();
			}
		});
		
		
		return ((Number)result).intValue(); 
	}

	public Category findByFilter(PropertyFilter filter) {
		return super.findByFilter(filter);
	}

}
